<template>
  <div id="ygy_queryEnterSituation">
    <!--<el-dropdown class="el-icon-dropdown">-->
    <!--<el-dropdown-item @click.native="Entering">委托书</el-dropdown-item>-->
    <!--</el-dropdown>-->
    <!-- <el-dropdown class="el-icon-dropdown" placement="bottom-start">
      <span>
        查询
        <i class="el-icon-arrow-down el-icon--right"></i>
      </span>
    <el-dropdown-menu slot="dropdown">-->
    <!-- <el-dropdown-item>补办</el-dropdown-item> -->
    <!-- <el-dropdown-item @click.native="OnTimeDeliveryRate">准时交车率</el-dropdown-item>
        <el-dropdown-item @click.native="QueryWudian">查询误点</el-dropdown-item>
        <el-dropdown-item @click.native="Ledger">台账</el-dropdown-item>
        <el-dropdown-item @click.native="InquiryAttorney">预约率查询-委托书</el-dropdown-item>
        <el-dropdown-item @click.native="contactMange0">预约率-车辆</el-dropdown-item>
    <el-dropdown-item @click.native="contactMange1">临近准时交车率</el-dropdown-item>-->
    <!--<el-dropdown-item @click.native="contactMange2">钣喷准时交车率</el-dropdown-item>-->
    <!-- <el-dropdown-item @click.native="contactMange3">钣喷快修交车率</el-dropdown-item>
        <el-dropdown-item @click.native="contactMange4">机修快保交车率</el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
    <el-dropdown class="el-icon-dropdown" placement="bottom-start">
      <span>
        汇总
        <i class="el-icon-arrow-down el-icon--right"></i>
      </span>
    <el-dropdown-menu slot="dropdown">-->
    <!-- <el-dropdown-item>补办</el-dropdown-item> -->
    <!-- <el-dropdown-item @click.native="VehicleConfluence">车型汇总</el-dropdown-item>
        <el-dropdown-item @click.native="PlateConfluence">车牌汇总</el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
    <el-dropdown class="el-icon-dropdown" placement="bottom-start">
      <span>
        明细
        <i class="el-icon-arrow-down el-icon--right"></i>
      </span>
    <el-dropdown-menu slot="dropdown">-->
    <!--  <el-dropdown-item>补办</el-dropdown-item> -->
    <!-- <el-dropdown-item @click.native="ProjectMaterialDetails">项目材料明细</el-dropdown-item>
        <el-dropdown-item @click.native="CustomerVehicleDetails">客户车辆明细</el-dropdown-item>
        <el-dropdown-item @click.native="ikeyFault">service key故障</el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
    <el-dropdown class="el-icon-dropdown" placement="bottom-start">
      <span>
        车辆维修
        <i class="el-icon-arrow-down el-icon--right"></i>
      </span>
      <el-dropdown-menu slot="dropdown">
        <el-dropdown-item @click.native="CarRepairThing">车辆维修信息统计</el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>-->

    <!--条件筛选-->
    <TopFilter ref="topFilter" :list="topFilterList" :cols="4" labelWidth="110" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>
    <ButtonArea align="right">
      <!-- <el-button size="small" type="primary" @click="getInformation">延保查询</el-button> -->
      <el-button type="primary" @click="historyFun">维修历史</el-button>
      <el-button type="primary" :disabled="enerdydisabled" @click="xnyLr">上传溯源信息</el-button>
      <el-button type="primary" @click="handleCheckServicePerformance">服务顾问业绩统计汇总</el-button>
      <el-button type="primary" :loading="loadingPrintOrder" icon="el-icon-printer" @click="printOrderClick">打印工单</el-button>
      <el-button type="primary" icon="el-icon-printer" :disabled="!isShow" @click="printBalanceClick">打印结算单</el-button>
      <el-dropdown trigger="click" @command="handleCommand">
        <el-button type="primary">
          查询功能
          <i class="el-icon-arrow-down el-icon--right"></i>
        </el-button>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item command="a">延保查询</el-dropdown-item>
          <el-dropdown-item command="b">误点查询</el-dropdown-item>
          <el-dropdown-item command="c">预约率查询</el-dropdown-item>
          <el-dropdown-item command="e">首保权益查询</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
      <!-- <el-button type="primary" @click="wdcxClick">误点查询</el-button> -->
    </ButtonArea>
    <!-- 列筛选-->
    <!-- :fetchapi="fetchApi"
      :datakey="'rows'"
    :params="fetchParams"-->
    <FilterTable
      ref="table"
      columnsRef="ygy_queryEnterSituation"
      :columns="columns"
      selectionType="single"
      :dataSource="tableDataList"
      :isMemoryPagination="true"
      :pageSize="20"
      :isExportExcel="isExportExcel"
      exportFileName="查询进厂情况导出表.xlsx"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="selectDataList"
      :isServerColumnsRef="true"
      :onSyncTableData="onSyncTableData"
    >
      <template slot="controls">
        <!-- <el-col class="enter" style="height:32px;">进厂台次:{{ enterSituationNum }}</el-col> -->
        <el-button v-show="showEnterSituationNum" size="small" type="text">进厂台次:{{ enterSituationNum }}</el-button>
        <!-- <el-button size="small" type="primary" @click="bookingRateClick">预约率查询</el-button> -->
        <el-button size="small" type="primary" @click="licenseClick">牌照汇总</el-button>
      </template>
    </FilterTable>
    <!-- <BaseDialog title="上传溯源信息" :visible.sync="XNYAttribute" destroyOnClose>
      <XNYAttribute :rowData="SBList" @close="closeXNY"></XNYAttribute>
    </BaseDialog> -->

    <!-- 维修历史 -->
    <Drawer :visible.sync="showRepairhistory" title="维修历史" width="1300" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <Repairhistory ref="Repairhistory" :getdata="onSelectCell" @close="closeRepairhistory" />
    </Drawer>

    <!-- 查询明细 -->
    <Drawer :visible.sync="labour" title="明细" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <labourModel :list="selectData" :repairParams="repairParams" @closeDialog="closeDialog"></labourModel>
    </Drawer>

    <!-- 打印结算单 -->
    <BaseDialog title="打印结算单" :visible.sync="prePrintDialogShow" :width="'40%'" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <printBalance
        :printBalanceData="printBalanceData"
        @close="
          val => {
            this.prePrintDialogShow = val;
          }
        "
      />
    </BaseDialog>

    <div v-if="printShowFee">
      <BasePrint ref="printFee" :data="printListFee" :showForwardText="orderPrintShowForwardText" template="templatePrintFee" />
    </div>
    <!--弹出页-->
    <BaseDialog :visible.sync="component.visible" :title="component.title" width="70%" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <component :is="componentName" :collapseStatus="status" :params="fetchParams" :formData="this.tableData" @close="closeComponentName"></component>
    </BaseDialog>

    <!--抽屉-->
    <Drawer
      :visible.sync="componentDrawer.visible"
      :title="componentDrawer.title"
      :width="920"
      destroyOnClose
      :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }"
    >
      <component :is="componentDrawerName" :collapseStatus="status" :params="fetchParams" :formData="this.tableData" @close="closeComponentDrawerName"></component>
    </Drawer>

    <!-- 服务顾问业绩统计汇总 -->
    <Drawer :visible.sync="summaryDialogVisible" title="服务顾问业绩统计汇总" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <serviceSummary :fetchParams="summaryFetchParams" @close="summaryDialogVisible = false" />
    </Drawer>
    <!-- 误点查询 -->
    <Drawer :visible.sync="showWDCXDrawer" title="误点查询" destroyOnClose :containerStyle="{ height: '100%', overflow: 'auto' }">
      <queryWudianModel :formData="editData" :type="this.componentDrawer.type" :allUser="this.columns.find(x => x.dataIndex === 'SERVICE_ADVISOR').editItems"></queryWudianModel>
    </Drawer>

    <!-- 首保权益查询 -->
    <Drawer :visible.sync="showSBQYDrawer" title="首保权益查询" destroyOnClose :containerStyle="{ height: '100%', overflow: 'auto' }">
      <querySBQYmodel @close="closeHandlerSBQY"> </querySBQYmodel>
    </Drawer>

    <!-- 牌照汇总 -->
    <BaseDialog :visible.sync="licenseVisible" title="牌照汇总" width="70%" destroyOnClose :containerStyle="{ height: 'calc(100% - 130px)' }">
      <TopFilter ref="ygy_licenseTopFilters" :list="licenseTopFilterList" :cols="2" @filterChange="ygy_changeHandler" />

      <FilterTable
        ref="ygy_licenseList"
        columnsRef="ygy_licenseList"
        :columns="license_columns"
        :dataSource="licenseDataList"
        :isMemoryPagination="true"
        :pageSize="20"
        :isSelectColumn="false"
        :isExportExcel="true"
        exportFileName="牌照汇总导出表.xlsx"
        :onColumnsChange="columns => (this.license_columns = columns)"
        :onRowSelectChange="() => {}"
      ></FilterTable>
    </BaseDialog>
    <!-- 预约率查询 -->
    <BaseDialog :visible.sync="bookingVisible" title="预约率查询" width="350px" destroyOnClose :containerStyle="{ height: 'calc(100%)' }">
      <div v-loading="bookingLoading">
        <p v-show="startTime && stopTime" style="padding: 10px 0">{{ startTime }}到{{ stopTime }}的记录</p>
        <FormPanel ref="bookingFormPanel" :list="bookingFormList" :cols="1" :labelWidth="110" :collapse="false" :isSubmitBtn="false" @formChange="bookingFormChangeHandle"></FormPanel>
        <p style="padding: 10px 0">预约率公式：</p>
        <p style="fontWeight: bold">预约率=预约车辆/(首保+保养+小修+行动+召回)车辆*100%</p>
        <br />
        <p style="padding: 10px 0">说明：</p>
        <p style="fontWeight: bold">取消完工审核会对统计结果有影响</p>
        <!-- <div style="text-align:center;">
          <el-button size="small" type="primary" @click="saveBookingDialog">确定</el-button>
          <el-button size="small" type="primary" @click="closeBookingDialog">取消</el-button>
        </div>-->
      </div>
    </BaseDialog>
  </div>
</template>

<script>
import Repairhistory from '@/pages/repair/repairReception/repairBusinessManger/historypop.vue';
import { dictionary } from '@/utils/dictMixin';
import { getOwnerCode } from '@/assets/js/auth';
import moment from 'moment';
// import XNYAttribute from '@/pages/repair/repairReception/submitForSettlement/xnyAttribute.vue';
// import { confirmAction, notifyAction, messageAction } from '@/utils';
import { getQueryEnterSituation, getAllUser, getQueryEnterSituationByLicense, getQueryEnterSituationNum, getQueryEnterSituationBooking } from '@/api/repair/queryStatistics/queryAccounts';
// 委托书
import enteringModel from './select/enteringModel';
// 准时交车率
import OnTimeDeliveryRateModel from './select/OnTimeDeliveryRateModel';
// 查询误点
import queryWudianModel from './select/queryWudianModel';
// 查询首保权益
import querySBQYmodel from './select/querySBQYmodel';
// 台账
import LedgerModel from './select/LedgerModel';
// 预约率查询-委托书
import InquiryAttorneyModel from './select/InquiryAttorneyModel';
// 预约率-车辆
import contactMange0Model from './select/contactMange0Model';
// 临近准时交车率
import contactMange1Model from './select/contactMange1Model';
// 钣喷准时交车率
// import contactMange2Model from './select/contactMange2Model';
// 钣喷快修交车率
import contactMange3Model from './select/contactMange3Model';
// 机修快保交车率
import contactMange4Model from './select/contactMange4Model';
// 车型总汇
import VehicleConfluenceModel from './select/VehicleConfluenceModel';
// 车牌总汇
import PlateConfluenceModel from './select/plateConfluenceModle';
// 项目材料明细
import ProjectMaterialDetailsModel from './select/ProjectMaterialDetailsModle';
// 客户车辆明细
import CustomerVehicleDetailsModle from './select/CustomerVehicleDetailsModle';
// ikey故障
import ikeyFaultModle from './select/ikeyFaultModle';
// 车辆维信信息统计
import CarRepairThingModle from './select/CarRepairThingModle';
import labourModel from '@/pages/repair/repairReception/repairBusinessManger/labourModel';
import { getUserListSelect } from '@/api/report/repair/repairreport';
import { exGetUrl, getRepairOrderPrintInfo } from '@/api/repair/repairReception/customer';

import { getDealerCompanyByCode } from '@/api/repair/repairReception/feesSettlement';
// 服务顾问业绩统计汇总
import serviceSummary from './summary';

// 省翻译
import getProvince from '@/api/customerRepair/customerInfo/ownerVehicleManagement';
import { searchRoleByCode } from '@/api/common/empSelect/index';
import dictCode from '@/utils/dictCode';
import { sleep } from '@/utils/index.js';

import printBalance from '@/pages/repair/repairReception/repairBusinessManger/printBalance.vue';
import { queryBlalanceInfo } from '@/api/repair/repairReception/repairBusinessManger';
import { findAllRepair } from '@/api/repair/basicParameters';
import { queryFdUploadStatusByRoNo } from '@/api/repair/repairReception/customer';
import { menuUserAction } from '@/api/repair/repairReception/repairBusinessManger';

export default {
  name: 'whmEntering',
  components: {
    enteringModel,
    labourModel,
    OnTimeDeliveryRateModel,
    queryWudianModel,
    querySBQYmodel,
    LedgerModel,
    InquiryAttorneyModel,
    contactMange0Model,
    contactMange1Model,
    // contactMange2Model,
    contactMange3Model,
    contactMange4Model,
    VehicleConfluenceModel,
    PlateConfluenceModel,
    ProjectMaterialDetailsModel,
    ikeyFaultModle,
    CustomerVehicleDetailsModle,
    CarRepairThingModle,
    // XNYAttribute,
    serviceSummary,
    Repairhistory,
    printBalance
  },
  mixins: [dictionary],
  data() {
    this.conf = { add: '新增', delete: '删除', edit: '编辑', show: '显示' };
    return {
      isExportExcel: false,
      startTime: '',
      stopTime: '',
      showEnterSituationNum: false,
      enterSituationNum: '',
      licenseVisible: false,
      bookingVisible: false,
      bookingLoading: false,
      bookingFormList: this.createBookingFormListList(),
      licenseDataList: [],
      estimatequery: '',
      showRepairhistory: false,
      PortalShow: false,
      onSelectCell: null,
      portalParmas: '',
      topFilterList: this.createTopFilterList(),
      licenseTopFilterList: this.createLicenseTopFilterList(),
      fetchParams: { xhrAbort: true },
      enerdydisabled: true,
      SBList: {},
      XNYAttribute: false,
      labour: false,
      visible: false,
      visible1: false,
      dialogTitle: '',
      fetchApi: getQueryEnterSituation,
      columns: this.createTableColumns(),
      license_columns: this.createLicenseColumns(),
      handleType: '',
      formData: [],
      tableData: [],
      ids: [],
      editData: [],
      status: [],
      selectData: [],
      componentName: null, // 组件的名称
      component: { visible: false, type: '', title: '' }, // 弹出面板的相关信息
      actions: { visible: false, type: '', title: '' }, // 弹出面板的相关信息
      componentDrawerName: null, // 抽屉组件名称
      componentDrawer: { visible: false, type: '', title: '' }, // 弹出抽屉面板的相关信息
      tableDataList: [], // table列表数据
      summaryDialogVisible: false, // 是否显示服务顾问业绩统计汇总弹窗
      summaryFetchParams: {}, // 传入服务业绩统计汇总弹窗的查询条件

      printShowFee: false,
      isPrint: true,
      isPrintJS: true,
      printBalanceData: [],
      prePrintDialogShow: false, // 结算单
      PrintDialogShow: false, // 工单
      printListLee: {},
      loadingPrintOrder: false,
      selectColumns: [],
      showWDCXDrawer: false,
      showSBQYDrawer: false,
      mainTableIsLoading: false, // 主table是否在请求(限制请求字数)

      allUsers: [],
      paramss: {
        username: '',
        password: '',
        'login-form-type': 'pwd'
      },
      visible2: false,
      finalUrl: '',
      repairParams: {} // 服务参数
    };
  },
  computed: {
    isShow() {
      // 结算单状态 - 确定是否显示打印结算单
      if (!this.selectColumns.length) return false;
      return this.selectColumns[0].RO_STATUS === 80491003;
    },
    // 打印工单是否显示预约字样
    orderPrintShowForwardText() {
      return this.printListFee.repairOrderMainInfo && this.printListFee.repairOrderMainInfo.BOOKING_ORDER_NO ? true : false;
    }
  },
  mounted() {
    // 分页
    // this.BaseTable = this.$refs.table.$refs.pageTable;
    this.initSelect();
    this.exGetUrl();
    this.queryRepairParams();
    this.menuUserAction();
  },
  methods: {
    async menuUserAction() {
      let res = await menuUserAction();
      console.log('menuUserAction', res);
      for (const item of res.data) {
        if (item.actionUrl == '/repair/queryStatistics/queryEnterSituation') {
          this.isExportExcel = true;
        }
      }
    },
    createLicenseColumns() {
      return [
        // {
        //   title: '操作',
        //   dataIndex: 'column-action',
        //   render: props => {
        //     return (
        //       <el-button size="mini" type="text" onClick={() => console.log(props.row)}>
        //         明细
        //       </el-button>
        //     );
        //   }
        // },
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        // {
        //   title: '台次',
        //   dataIndex: 'TAIWANESE',
        //   sorter: true,
        //   filter: true,
        //   showOverflowTooltip: true,
        //   filterType: 'number'
        // },
        {
          title: ' 牌照号',
          dataIndex: 'LICENSE',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        {
          title: '车型名称',
          dataIndex: 'MODEL',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        {
          title: '合计金额',
          dataIndex: 'SUM_AMOUNT',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'number'
        },
        {
          title: '客户名称',
          dataIndex: 'OWNER_NAME',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        {
          title: '客户电话',
          dataIndex: 'PHONE',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        {
          title: '客户移动电话',
          dataIndex: 'MOBILE',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        }
      ];
    },
    createBookingFormListList() {
      return [
        // {
        //   type: 'INPUT_NUMBER',
        //   label: '维修工单总数',
        //   fieldName: 'workGroupCode',
        //   placeholder: '',
        //   render: val => {
        //     return <span>{`${moment}记录`} </span>;
        //   }
        // },
        {
          type: 'INPUT_NUMBER',
          label: '维修工单总数',
          fieldName: 'TOTAL_NUM',
          placeholder: ''
        },
        {
          type: 'INPUT_NUMBER',
          label: '预约单维护工单数',
          fieldName: 'BOOKING_NUM',
          placeholder: ''
        },
        {
          type: 'INPUT_NUMBER',
          label: '预约率',
          fieldName: 'BOOKING_RATE',
          style: { width: 'calc(100% - 50px)' },
          placeholder: '',
          descOptions: {
            content: '%'
          }
        }

        // {
        //   type: 'DATE',
        //   dateType: 'datetime',
        //   label: '预计完工时间',
        //   fieldName: 'estimateEndTime',
        //   initialValue: moment().format('YYYY-MM-DD HH:mm:ss')
        // }
      ];
    },

    createLicenseTopFilterList() {
      return [
        {
          type: 'RADIO',
          label: '是否包含无车牌汇总',
          fieldName: 'isLicense',
          selfCols: 3,
          labelWidth: '130px',
          itemList: [
            { text: '是', value: '10041001' },
            { text: '否', value: '10041002' }
          ],
          initialValue: '10041002'
        }
      ];
    },

    async ygy_changeHandler(val) {
      let formParams = await this.$refs.topFilter.GET_FORM_DATA();
      // await sleep(100);
      this.$refs.ygy_licenseList && this.$refs.ygy_licenseList.START_LOADING();
      console.log('formParams[1]:', formParams[1]);
      formParams[1].isLicense = this.licenseTopFilterList.find(x => x.fieldName == 'isLicense').initialValue;
      try {
        let res = await getQueryEnterSituationByLicense(formParams[1] || {});
        if (res.resultCode == 200) {
          this.licenseDataList = res.data;
          console.log(res, 'getQueryEnterSituationByLicense');
        }
      } catch (err) {
        console.log(err, '查询牌照数据失败');
      } finally {
        this.$refs.ygy_licenseList.STOP_LOADING();
      }

      console.log('val:', val);
      const isLicense = this.licenseTopFilterList.find(x => x.fieldName === 'isLicense').initialValue;
      console.log('isLicense:', isLicense);
    },
    onSyncTableData(val) {
      // 表格数据变化触发
      // 过滤台次
      // 规则：同一天相同的vin码只算一个台次。起止日期
      console.log(val, 'onSyncTableData');
      let dateRes = {};
      let dateStr = '';
      let totalNum = 0;
      val.forEach(x => {
        // 按日期生成数据：二维数组
        let vinArr = [];
        x.RO_CREATE_DATE && (dateStr = x.RO_CREATE_DATE.toString().substring(0, 10));

        if (!dateRes.hasOwnProperty(dateStr)) {
          dateRes[dateStr] = [];
        }
        if (!dateRes[dateStr].includes(x.VIN)) {
          dateRes[dateStr].push(x.VIN);
        }
      });
      console.log(dateRes);

      for (const key in dateRes) {
        if (dateRes.hasOwnProperty(key)) {
          const element = dateRes[key];
          // console.log(element);
          totalNum += element.length;
        }
      }
      console.log(totalNum);
      this.enterSituationNum = totalNum;

      // // 组织二维数组格式
      // let dateArr = [];
      // let dateItem = [];
      // val.forEach(x=>{
      //   x.RO_CREATE_DATE // 不可以，数据如果没有排序过，无法觉得放那个数组
      // })
    },
    handleCommand(command) {
      if (command == 'a') {
        this.getInformation();
      } else if (command == 'b') {
        this.wdcxClick();
      } else if (command == 'c') {
        this.bookingRateClick();
      } else if (command == 'e') {
        this.querySBQYclick();
      }
    },
    async bookingRateClick() {
      let formParams = await this.$refs.topFilter.GET_FORM_DATA();
      this.bookingVisible = true;
      this.bookingLoading = true;
      if (formParams[1].startTime) {
        this.startTime = moment(formParams[1].startTime).format('YYYY-MM-DD');
      } else {
        this.startTime = '';
      }
      if (formParams[1].stopTime) {
        this.stopTime = moment(formParams[1].stopTime).format('YYYY-MM-DD');
      } else {
        this.stopTime = '';
      }
      try {
        this.bookingFormList.find(x => x.fieldName == 'BOOKING_RATE').initialValue = ''; // 先清空上次数据
        let res = await getQueryEnterSituationBooking(formParams[1] || {});
        if (res.resultCode == 200) {
          let obj = Object.assign({}, ...res.data);
          console.log(obj, 'getQueryEnterSituationBooking');
          console.log(res, 'getQueryEnterSituationBooking');
          this.bookingFormList.find(x => x.fieldName == 'TOTAL_NUM').initialValue = obj.TOTAL_NUM;
          this.bookingFormList.find(x => x.fieldName == 'BOOKING_NUM').initialValue = obj.BOOKING_NUM;

          if (obj.TOTAL_NUM) {
            if (obj.BOOKING_NUM !== undefined) {
              this.bookingFormList.find(x => x.fieldName == 'BOOKING_RATE').initialValue = ((obj.BOOKING_NUM / obj.TOTAL_NUM) * 100).toFixed(2);
            }
          }
        }
      } catch (err) {
        console.log(err, '查询预约率数据失败');
      } finally {
        this.bookingLoading = false;
      }
    },
    async licenseClick() {
      let formParams = await this.$refs.topFilter.GET_FORM_DATA();
      this.licenseVisible = true;
      // await sleep(100);
      this.$refs.ygy_licenseList && this.$refs.ygy_licenseList.START_LOADING();
      console.log('formParams[1]:', formParams[1]);
      formParams[1].isLicense = this.licenseTopFilterList.find(x => x.fieldName == 'isLicense').initialValue;
      try {
        let res = await getQueryEnterSituationByLicense(formParams[1] || {});
        if (res.resultCode == 200) {
          this.licenseDataList = res.data;
          console.log(res, 'getQueryEnterSituationByLicense');
        }
      } catch (err) {
        console.log(err, '查询牌照数据失败');
      } finally {
        this.$refs.ygy_licenseList.STOP_LOADING();
      }
    },
    bookingFormChangeHandle() {},
    saveBookingDialog() {
      this.bookingVisible = false;
    },
    closeBookingDialog() {
      this.bookingVisible = false;
    },
    async wdcxClick() {
      let filterData = await this.$refs.topFilter.GET_FORM_DATA();
      if (filterData[1].startTime || filterData[1].stopTime) {
        this.showWDCXDrawer = true;
        this.QueryWudian();
      } else {
        this.$notify.warning({ title: '提示信息', message: '请先选择时间！' });
      }
    },
    querySBQYclick() {
      this.showSBQYDrawer = true;
    },
    // 打印工单
    async printOrderClick() {
      if (this.selectColumns.length > 0) {
        let fdRepairParams = this.repairParams['9403'];
        let roNo = this.selectColumns[0].RO_NO;
        let repairType = this.selectColumns[0].REPAIR_TYPE_CODE;
        // console.log(fdRepairParams, roNo, repairType, 'hexj111');
        if (fdRepairParams == 1 && (repairType == 1 || repairType == 'G')) {
          let fdRes = {};
          try {
            fdRes = await queryFdUploadStatusByRoNo({ roNo });
          } catch (err) {
            console.log(err, '查询fd状态失败');
          }
          if (fdRes.resultCode == 200) {
            if (fdRes.data.FD_STATUS != 10041001) {
              return this.$notify.warning({
                title: '提示信息',
                message: '此工单未上传FD不允许打印委托书'
              });
            }
          }
        }
        // 获取数据
        this.loadingPrintOrder = true;
        await this.printBalance();
        this.loadingPrintOrder = false;
        this.printShowFee = true;
        this.$nextTick(() => {
          this.$refs.printFee.EXCUTE_PRINT();
        });
      } else {
        this.$notify({
          title: '提示信息',
          message: '请选择一条数据',
          type: 'warning'
        });
      }
    },

    // 打印结算单
    async printBalanceClick() {
      if (this.selectColumns.length > 0) {
        // 获取数据
        this.printBalanceData.RO_NO = this.selectColumns[0].RO_NO;
        this.printBalanceData.OWNER_NO = this.selectColumns[0].OWNER_NO;
        this.printBalanceData['VIN'] = this.selectColumns[0].VIN;
        await this.queryPay();
        this.prePrintDialogShow = true;
      } else {
        this.$notify({
          title: '提示信息',
          message: '请选择一条数据',
          type: 'warning'
        });
      }
    },
    async printBalance() {
      const roNo = this.selectColumns[0].RO_NO;
      console.log('66666666666666666666666', roNo);
      let res = await getRepairOrderPrintInfo(roNo); // 获取打印主数据
      if (res.resultCode == 200) {
        this.printListFee = _.cloneDeep(res.data);
        for (const key in this.printListFee) {
          if (this.printListFee.hasOwnProperty(key)) {
            const element = this.printListFee[key];
            this.$set(this.printListFee, key, element);
          }
        }
        // this.printListFee['companyNameCn'] = res1.data.companyInfo.companyNameCn;
        // this.printListFee['companyNameEn'] = res1.data.companyInfo.companyNameEn;
        // this.printListFee['addressZh'] = res1.data.companyInfo.addressZh;
        // this.printListFee['addressEn'] = res1.data.companyInfo.addressEn;
        // this.printListFee['phone'] = res1.data.companyInfo.phone;
        // this.printListFee['zipCode'] = res1.data.companyInfo.zipCode;
        // this.printListFee['fax'] = res1.data.companyInfo.fax;
        if (this.printListFee.repairOrderMainInfo.RO_CREATE_DATE != '') {
          this.printListFee.repairOrderMainInfo.RO_CREATE_DATE = moment(this.printListFee.repairOrderMainInfo.RO_CREATE_DATE).format('YYYY-MM-DD HH:mm:ss');
        }
        if (this.printListFee.repairOrderMainInfo.END_TIME_SUPPOSED != '') {
          this.printListFee.repairOrderMainInfo.END_TIME_SUPPOSED = moment(this.printListFee.repairOrderMainInfo.END_TIME_SUPPOSED).format('YYYY-MM-DD HH:mm:ss');
        }

        let allUsers = this.allUsers;
        console.log(allUsers, 'allUsers');
        allUsers.forEach(x => {
          if (this.printListFee.repairOrderMainInfo.SERVICE_ADVISOR === x.value + '') {
            this.printListFee.repairOrderMainInfo.SERVICE_ADVISOR = x.text;
          }
        });
        let serviceMajordom = { role: dictCode.SERVE_MAJORDOM }; // 服务总监
        const serviceMajordomRes = await searchRoleByCode(serviceMajordom);
        if (serviceMajordomRes.data.length > 0) {
          this.printListFee.repairOrderMainInfo.SERVE_MAJORDOM = serviceMajordomRes.data[0].employeeName;
        }
        let oilRemain = this.printListFee.repairOrderMainInfo.OIL_REMAIN;
        const oilRes = this.createDictList('8045');

        for (var i = 0; i < oilRes.length; i++) {
          if (oilRemain === oilRes[i].value) {
            this.printListFee.repairOrderMainInfo.OIL_REMAIN = oilRes[i].text;
          }
        }

        allUsers.forEach(x => {
          if (x.value + '' === this.printListFee.repairOrderMainInfo.TECHNICIAN) {
            this.printListFee.repairOrderMainInfo.TECHNICIAN = x.text;
          }
          if (x.value + '' === this.printListFee.repairOrderMainInfo.CREATED_BY) {
            this.printListFee.repairOrderMainInfo.CREATED_BY = x.text;
          }

          for (var j = 0; j < this.printListFee.printRepairLabour.length; j++) {
            if (x.value + '' === this.printListFee.printRepairLabour[j].TECHNICIAN) {
              this.printListFee.printRepairLabour[j].TECHNICIAN = x.text;
            }
          }
        });
        const dealerCode = await getDealerCompanyByCode();
        this.printListFee.dealerAddress = dealerCode.data.address1;
        this.printListFee.phone = dealerCode.data.ascPhone;
        console.log(this.printListFee, 'printListFee', res.data);
        console.log(dealerCode, 'dealerCode');
        this.isPrint = false;
      }
    },
    // 结算单信息查询
    async queryPay() {
      let newStr = [];
      let roNo = this.selectColumns[0].RO_NO;
      const res = await queryBlalanceInfo(roNo);
      this.printBalanceData = Object.assign({}, this.printBalanceData, res.data[0]);
      console.log(this.printBalanceData);
      console.log(res.data[0]);
      if (res.data.length) {
        for (let [key, val] of Object.entries(res.data[0])) {
          let param = {
            fieldName: this.camelcase(key),
            value: val
          };
          newStr.push(param);
        }
        console.log(newStr);
        let formList = this.createBottomFilterList();
        let formFieldNames = formList.map(x => x.fieldName);
        newStr.forEach(x => {
          if (formFieldNames.includes(x.fieldName)) {
            let target = formList.find(k => k.fieldName === x.fieldName);
            if (!target) return;
            if (x.fieldName === 'receiveAmount' || x.fieldName === 'derateAmount') {
              target.initialValue = Number(x.value).toFixed(2);
            } else {
              target.initialValue = x.value;
            }
          }
        });
      }
    },
    // 字符串转驼峰
    camelcase(str) {
      let arr = str.split('_');
      let upper = arr.map((val, index) => {
        let lowStr = val.toLowerCase();
        if (index) {
          lowStr = lowStr.charAt(0).toLocaleUpperCase() + lowStr.slice(1);
        }
        return lowStr;
      });
      return upper.join('');
    },
    createBottomFilterList() {
      return [
        {
          type: 'INPUT',
          label: '结算单号',
          fieldName: 'balanceNo',
          disabled: this.isDisabled
        },
        {
          type: 'INPUT',
          label: '结算时间',
          fieldName: 'balanceTime',
          disabled: this.isDisabled
        },
        {
          type: 'INPUT',
          label: '优惠模式',
          palceholder: '请选择',
          fieldName: 'discountModeName',
          disabled: this.isDisabled
        },
        {
          type: 'SELECT',
          label: '结算员',
          palceholder: '请选择',
          fieldName: 'balanceHandler',
          disabled: this.isDisabled,
          itemList: []
        },
        {
          type: 'INPUT',
          label: '原结算单号',
          fieldName: 'lastBalanceNo',
          disabled: this.isDisabled
        },
        {
          type: 'INPUT_NUMBER',
          label: '应收金额',
          fieldName: 'receiveAmount',
          precision: 2,
          disabled: this.isDisabled
        },
        {
          type: 'INPUT_NUMBER',
          label: '减免金额',
          fieldName: 'derateAmount',
          precision: 2,
          disabled: this.isDisabled
        }
      ];
    },
    // 获取各系统的地址
    async exGetUrl() {
      let res = await exGetUrl({ fdupload: 'fdupload', fdreceieve: 'fdreceieve', estimate: 'estimate' });
      if (res.data) {
        // this.fdupload = res.data.fdupload;
        // this.fdreceieve = res.data.fdreceieve;
        this.estimatequery = res.data.estimate;
      }
    },
    // 延保估算信息查询
    getInformation() {
      let ownerCode = getOwnerCode();
      if (this.tableData.length > 0) {
        let vin = this.tableData[0].VIN;
        let f = document.createElement('form'); // 表单
        f.style.display = 'none'; // 显示为none
        f.target = '_blank'; // 打开新页面
        f.action = this.estimatequery + ownerCode + '&vin=' + vin; // 地址
        f.method = 'post';
        document.body.appendChild(f);
        f.submit();
      } else {
        this.$notify({
          title: '提示信息',
          message: '请选择一条数据',
          type: 'warning'
        });
      }
    },
    // 维修历史
    historyFun() {
      if (!this.tableData.length) {
        return this.$notify({
          title: '提示信息',
          message: '请选择一条数据',
          type: 'warning'
        });
      }
      this.onSelectCell = {
        VIN: this.tableData[0].VIN
      };
      this.showRepairhistory = true;
    },

    closeRepairhistory() {
      this.showRepairhistory = false;
    },
    async initSelect() {
      // 获取所有人员接口，包括离职人员。用于翻译
      let res5 = (await getAllUser()).data.map(x => ({ value: x.userId + '', text: x.employeeName }));
      this.columns.find(x => x.dataIndex === 'SERVICE_ADVISOR').editItems = res5;
      this.allUsers = res5;
      // 使用手动输入来筛选过滤
      // this.columns.find(x => x.dataIndex === 'SERVICE_ADVISOR').filterItems = res5;
      this.columns.find(x => x.dataIndex === 'CREATED_BY').editItems = res5;
      this.columns.find(x => x.dataIndex === 'CREATED_BY').filterItems = res5;
      this.columns.find(x => x.dataIndex === 'BALANCE_HANDLER').editItems = res5;
      this.columns.find(x => x.dataIndex === 'BALANCE_HANDLER').filterItems = res5;

      // this.columns.find(x => x.dataIndex === 'DELIVERER').editItems = res5;
      // this.columns.find(x => x.dataIndex === 'DELIVERER').filterItems = res5;
      let obj = { role: dictCode.SERVICE_CONSULTANT };
      const res = await searchRoleByCode(obj);
      const filterData = res.data.map(x => ({ text: x.employeeName, value: x.userId + '' }));
      this.columns.find(x => x.dataIndex === 'SERVICE_ADVISOR').filterItems = filterData;
    },

    createTopFilterList() {
      return [
        // {
        //   type: 'RADIO',
        //   label: '',
        //   labelWidth: '120px',
        //   style: { minWidth: '300px' },
        //   fieldName: 'flag',
        //   initialValue: '1',
        //   itemList: [
        //     { value: '1', text: '按照日期查询' },
        //     { value: '2', text: '按牌照号查询' },
        //     { value: '3', text: '按底盘号查询' }
        //   ],
        //   selfCols: 3,
        //   change: val => {
        //     // let paramFlag = this.topFilterList.find(x => x.fieldName === 'flag').initialValue;
        //     // this.fetchParams = { ...this.fetchParams, flag: paramFlag };
        //     if (val === '1') {
        //       this.topFilterList.find(x => x.fieldName === 'startTime|stopTime').hidden = false;
        //       this.topFilterList.find(x => x.fieldName === 'LICENSE').hidden = true;
        //       this.topFilterList.find(x => x.fieldName === 'VIN').hidden = true;
        //       this.topFilterList.find(x => x.fieldName === 'LICENSE').initialValue = '';
        //       this.topFilterList.find(x => x.fieldName === 'VIN').initialValue = '';
        //     }
        //     if (val === '2') {
        //       this.topFilterList.find(x => x.fieldName === 'startTime|stopTime').hidden = true;
        //       this.topFilterList.find(x => x.fieldName === 'LICENSE').hidden = false;
        //       this.topFilterList.find(x => x.fieldName === 'VIN').hidden = true;
        //       this.topFilterList.find(x => x.fieldName === 'startTime|stopTime').initialValue = '';
        //       this.topFilterList.find(x => x.fieldName === 'VIN').initialValue = '';
        //     }
        //     if (val === '3') {
        //       this.topFilterList.find(x => x.fieldName === 'startTime|stopTime').hidden = true;
        //       this.topFilterList.find(x => x.fieldName === 'LICENSE').hidden = true;
        //       this.topFilterList.find(x => x.fieldName === 'VIN').hidden = false;
        //       this.topFilterList.find(x => x.fieldName === 'startTime|stopTime').initialValue = '';
        //       this.topFilterList.find(x => x.fieldName === 'LICENSE').initialValue = '';
        //     }
        //   }
        // },
        {
          type: 'RANGE_DATE',
          label: '送修起止日期',
          style: { minWidth: '200px' },
          fieldName: 'startTime|stopTime',
          initialValue: [
            moment(new Date())
              .startOf('month')
              .format('YYYY-MM-DD') + ' 00:00:00',
            moment(new Date()).format('YYYY-MM-DD') + ' 00:00:00'
          ],
          rules: [],
          hidden: false
        },
        {
          type: 'INPUT',
          label: '牌照号',
          fieldName: 'LICENSE',
          hidden: false,
          rules: []
        },
        {
          type: 'INPUT',
          label: '底盘号',
          fieldName: 'VIN',
          hidden: false,
          rules: []
        },
        {
          type: 'INPUT',
          label: '委托书号',
          fieldName: 'RO_NO'
        },
        {
          type: 'SELECT',
          label: '委托书类别',
          fieldName: 'REPAIR_TYPE',
          placeholder: '请选择...',
          initialValue: '1',
          itemList: [
            { text: '全部', value: '1' },
            { text: '保险类委托书', value: '2' },
            { text: '首保类委托书', value: '3' },
            { text: '索赔类委托书', value: '4' },
            { text: '其他类委托书', value: '5' },
            { text: '免费类委托书', value: '6' }
          ]
        },
        // {
        //   type: 'SELECT',
        //   label: '工单状态',
        //   fieldName: 'RO_STATUS',
        //   placeholder: '请选择...',
        //   initialValue: '',
        //   itemList: [
        //     { text: '全部', value: '' },
        //     { text: '在修', value: '80491001' },
        //     { text: '已交车，待结算', value: '80491002' },
        //     { text: '已结算', value: '80491003' },
        //     { text: '估价导入', value: '80491004' },
        //     { text: 'APP预生成', value: '80491005' }
        //   ]
        // },
        // {
        //   type: 'MULTIPLE_SELECT',
        //   label: '工单状态',
        //   fieldName: 'RO_STATUS',
        //   placeholder: '请选择',
        //   itemList: this.createDictList('8049'),
        //   initialValue: ''
        // },
        // {
        //   type: 'SELECT',
        //   label: '误点查询',
        //   fieldName: 'LateSelect',
        //   placeholder: '请选择...',
        //   initialValue: '1',
        //   itemList: [
        //     { text: '否', value: '1' },
        //     { text: '是', value: '2' }
        //   ]
        // },
        {
          type: 'INPUT',
          label: '进厂故障描述',
          fieldName: 'RO_TROUBLE_DESC'
        },
        {
          type: 'INPUT',
          label: '车型代码',
          fieldName: 'MODEL_CODE'
        },
        {
          type: 'INPUT',
          label: '车系代码',
          fieldName: 'SERIES_CODE'
        }
      ];
    },
    createTableColumns() {
      return [
        {
          title: '操作',
          dataIndex: 'column-action',
          render: props => {
            return (
              <el-button size="mini" type="text" onClick={() => this.repairLabour(props.row)}>
                明细
              </el-button>
            );
          }
        },
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        // {
        //   title: '台次',
        //   dataIndex: 'TAIWANESE',
        //   sorter: true,
        //   filter: true,
        //   showOverflowTooltip: true,
        //   filterType: 'number'
        // },
        {
          title: '委托书编号',
          dataIndex: 'RO_NO',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        {
          title: '维修类别',
          dataIndex: 'REPAIR_TYPE_NAME',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        {
          title: '维修类型',
          dataIndex: 'REPAIR_TYPE_CODE',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        {
          title: '客户名称',
          dataIndex: 'OWNER_NAME',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        {
          title: '客户移动电话',
          dataIndex: 'MOBILE',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        {
          title: '客户电话',
          dataIndex: 'PHONE',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        {
          title: '客户地址',
          dataIndex: 'ADDRESS',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        {
          title: '联系人',
          dataIndex: 'DELIVERER',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        {
          title: '联系人移动电话',
          dataIndex: 'DELIVERER_MOBILE',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        {
          title: '联系人电话',
          dataIndex: 'DELIVERER_PHONE',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },

        {
          title: '牌照号',
          dataIndex: 'LICENSE',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        {
          title: '底盘号',
          dataIndex: 'VIN',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        {
          title: '电子首保卡号',
          dataIndex: 'EFW_CARD',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        {
          title: '工单状态',
          dataIndex: 'RO_STATUS',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('8049'),
          dictItems: this.createDictList('8049'),
          render: props => {
            return <span>{this.createDictText(props.row.RO_STATUS, '8049')}</span>;
          }
        },
        {
          title: '结算状态',
          dataIndex: 'BALANCE_STATUS',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'checkbox',
          filterItems: [
            { text: '在修', value: '在修' },
            { text: '已交车，待结算', value: '已交车，待结算' },
            { text: '结清', value: '结清' },
            { text: '未结清', value: '未结清' },
            { text: '欠账', value: '欠账' }
          ]
        },
        {
          title: '预约单号',
          dataIndex: 'BOOKING_ORDER_NO',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        {
          title: '车系代码',
          dataIndex: 'SERIES_CODE',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        {
          title: '车系',
          dataIndex: 'SERIES_NAME',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        {
          title: '车型代码',
          dataIndex: 'MODEL_CODE',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        {
          title: '车型',
          dataIndex: 'MODEL',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },

        {
          title: '约定交车时间',
          dateFormat: 'yyyy-MM-dd HH:mm:ss',
          dataIndex: 'END_TIME_SUPPOSED',
          width: 150,
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'date-range',
          exportFormat: {
            t: 'd'
          }
        },
        {
          title: '开单日期',
          dataIndex: 'RO_CREATE_DATE',
          width: 150,
          dateFormat: 'yyyy-MM-dd HH:mm:ss',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'date-range',
          editable: false,
          editType: 'date-picker',
          exportFormat: {
            t: 'd'
          }
        },
        {
          title: '审核日期',
          dataIndex: 'FOR_BALANCE_TIME',
          width: 150,
          dateFormat: 'yyyy-MM-dd HH:mm:ss',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'date-range',
          editable: false,
          editType: 'date-picker',
          exportFormat: {
            t: 'd'
          }
        },
        {
          title: '结算日期',
          dataIndex: 'BALANCE_TIME',
          width: 150,
          dateFormat: 'yyyy-MM-dd HH:mm:ss',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'date-range',
          editable: false,
          editType: 'date-picker',
          exportFormat: {
            t: 'd'
          }
        },
        {
          title: '结清日期',
          dataIndex: 'SQUARE_DATE',
          width: 150,
          dateFormat: 'yyyy-MM-dd HH:mm:ss',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'date-range',
          editable: false,
          editType: 'date-picker',
          exportFormat: {
            t: 'd'
          }
        },
        // {
        //   title: '是否结清',
        //   dataIndex: 'PAY_OFF',
        //   sorter: true,
        //   filter: true,
        //   showOverflowTooltip: true,
        //   filterType: 'input'
        // },

        {
          title: '其他费1',
          dataIndex: 'QT1',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'number',
          summation: true,
          precision: 2
        },
        {
          title: '其他费2',
          dataIndex: 'QT2',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'number',
          summation: true,
          precision: 2
        },
        {
          title: '其他费3',
          dataIndex: 'QT3',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'number',
          summation: true,
          precision: 2
        },
        {
          title: '工时费',
          dataIndex: 'REAL_LABOUR_FEE',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'number',
          summation: true,
          precision: 2
        },
        {
          title: '维修材料费',
          dataIndex: 'PAR_REAL_SUM',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'number',
          summation: true,
          precision: 2
        },
        {
          title: '合计金额',
          dataIndex: 'SUM_AMOUNT',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'number',
          summation: true,
          precision: 2
        },
        {
          title: '合计税额',
          dataIndex: 'TAX_AMOUNT',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'number',
          summation: true,
          precision: 2
        },

        {
          title: '包工方式',
          dataIndex: 'BG_TYPE',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('8145'),
          dictItems: this.createDictList('8145')
        },
        {
          title: '包工费',
          dataIndex: 'BGF',
          sorter: true,
          filter: true,
          filterType: 'number',
          precision: 2,
          summation: true,
          align: 'right',
          render: props => {
            return <span>{Number(props.row.BGF).toFixed(2)}</span>;
          }
        },

        {
          title: '施救费',
          dataIndex: 'SJF',
          sorter: true,
          filter: true,
          filterType: 'number',
          precision: 2,
          summation: true,
          align: 'right',
          render: props => {
            return <span>{Number(props.row.SJF).toFixed(2)}</span>;
          }
        },

        {
          title: '累计维修次数',
          dataIndex: 'HISTORY_REPAIR_TIMES',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'number'
        },
        {
          title: '累计维修金额',
          dataIndex: 'HISTORY_REPAIR_AMOUNT',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'number'
        },
        {
          title: '服务顾问',
          dataIndex: 'SERVICE_ADVISOR',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'checkbox',
          filterItems: [],
          editType: 'select',
          editItems: []
        },
        {
          title: '专属服务顾问',
          dataIndex: 'LXT_SERVICE_ADVISOR',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        {
          title: '客户证件号码',
          dataIndex: 'CERTIFICATE_NO',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        // {
        //   title: '送修人',
        //   dataIndex: 'DELIVERER',
        //   sorter: true,
        //   filter: true,
        //   showOverflowTooltip: true,
        //   filterType: 'checkbox',
        //   filterItems: [],
        //   editType: 'select',
        //   editItems: []
        // },
        {
          title: '操作员',
          dataIndex: 'CREATED_BY',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: [],
          showOverflowTooltip: true
        },
        {
          title: '结算员',
          dataIndex: 'BALANCE_HANDLER',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'checkbox',
          filterItems: [],
          editType: 'select',
          editItems: []
        },
        {
          title: '行驶里程',
          dataIndex: 'IN_MILEAGE',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'number'
        },
        {
          title: '客户级别',
          dataIndex: 'CUSTOMER_LEVEL',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('8103'),
          dictItems: this.createDictList('8103'),
          render: props => {
            return <span>{this.createDictText(props.row.CUSTOMER_LEVEL, '8103')}</span>;
          }
        },
        {
          title: '进厂故障描述',
          dataIndex: 'RO_TROUBLE_DESC',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },

        {
          title: '保险截止日期',
          dataIndex: 'INSURANCE_END_DATE',
          width: 150,
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'date-range',
          editable: false,
          editType: 'date-picker',
          exportFormat: {
            t: 'd'
          }
        },

        {
          title: '升级编号',
          dataIndex: 'ACTIVITY_CODE',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },

        {
          title: '备注',
          dataIndex: 'REMARK',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        {
          title: 'JD标识',
          dataIndex: 'JD_FLAG',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'checkbox',
          filterItems: [
            { text: '是', value: '是' },
            { text: '否', value: '否' }
          ]
        },
        {
          title: '班组',
          dataIndex: 'WORKGROUP_NAME',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        {
          title: '购车日期',
          dataIndex: 'SALES_DATE',
          width: 150,
          dateFormat: 'yyyy-MM-dd',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'date-range',
          exportFormat: {
            t: 'd'
          }
        },

        {
          title: '方便联系时间',
          dataIndex: 'CONCAT_TIME',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          showOverflowTooltip: true,
          filterItems: this.createDictList('8117'),
          dictItems: this.createDictList('8117')
        },

        {
          title: '服务包',
          dataIndex: 'SERVICE_PKG_CODE',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('8030'),
          render: props => {
            return <span>{this.createDictText(props.row.REPAIR_PACKAGE, '8030')}</span>;
          }
        },
        {
          title: '尊享/悦享',
          dataIndex: 'ZX_OR_YX',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'checkbox',
          filterItems: [
            { text: '尊享', value: '尊享' },
            { text: '悦享', value: '悦享' }
          ]
        },
        {
          title: '延保标识',
          dataIndex: 'IS_YB',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1004'),
          dictItems: this.createDictList('1004'),
          render: props => {
            return <span>{this.createDictText(props.row.IS_YB, '1004')}</span>;
          }
        },

        {
          title: '新车送保',
          dataIndex: 'IS_XB',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1004'),
          dictItems: this.createDictList('1004'),
          render: props => {
            return <span>{this.createDictText(props.row.IS_XB, '1004')}</span>;
          }
        },

        {
          title: '会员卡号',
          dataIndex: 'MEMBER_NO',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },

        {
          title: '尊享·悦享60分',
          dataIndex: 'IS_QUICK_REPAIR',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1004'),
          dictItems: this.createDictList('1004'),
          render: props => {
            return <span>{this.createDictText(props.row.IS_QUICK_REPAIR, '1004')}</span>;
          }
        },

        {
          title: '本公司售车',
          dataIndex: 'IS_SELF_COMPANY',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'checkbox',
          filterItems: [
            { text: '是', value: '是' },
            { text: '否', value: '否' }
          ]
        },

        {
          title: '省',
          dataIndex: 'PROVINCE',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input',
          dictItems: this.getAllProvince()
        },
        {
          title: '市',
          dataIndex: 'CITY',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input',
          dictItems: this.getAllCity()
        },
        {
          title: '县',
          dataIndex: 'DISTRICT',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input',
          dictItems: this.getAllDistrict()
        }
      ];
    },
    repairLabour(row) {
      this.selectData = row;
      this.labour = true;
    },
    closeDialog() {
      this.labour = false;
    },
    // 准时交车率
    OnTimeDeliveryRate() {
      // if (!this.selectData) {
      //   notifyAction('请选择一项数据', 'warning');
      //   return;
      // }
      // if (this.selectData.cLock === 1) {
      //   notifyAction('该卡已被锁定，请先解锁！', 'warning');
      //   return;
      // }
      let res = this.topFilterList.find(x => x.fieldName === 'startTime|stopTime').initialValue;
      this.editData = res;
      this.componentName = OnTimeDeliveryRateModel;
      this.component = { visible: true, type: 'edit', title: '准时交车率' };
    },
    async QueryWudian() {
      // this.editData = this.selectData;
      let res = this.topFilterList.find(x => x.fieldName === 'startTime|stopTime').initialValue;
      console.log(`startTime|stopTime ${res}`);
      let filterData = await this.$refs.topFilter.GET_FORM_DATA();
      this.editData = { 'startTime|stopTime': res, startTime: filterData[1].startTime, stopTime: filterData[1].stopTime };
      // this.componentDrawerName = queryWudianModel;
      // this.componentDrawer = { visible: true, type: 'edit', title: '查询误点' };
    },
    Ledger() {
      let res = this.topFilterList.find(x => x.fieldName === 'startTime|stopTime').initialValue;
      this.editData = res;
      this.componentDrawerName = LedgerModel;
      this.componentDrawer = { visible: true, type: 'edit', title: '台账' };
    },
    InquiryAttorney() {
      let res = this.topFilterList.find(x => x.fieldName === 'startTime|stopTime').initialValue;
      this.editData = res;
      this.componentName = InquiryAttorneyModel;
      this.component = { visible: true, type: 'edit', title: '预约率查询-委托书' };
    },
    contactMange0() {
      let res = this.topFilterList.find(x => x.fieldName === 'startTime|stopTime').initialValue;
      this.editData = res;
      this.componentName = contactMange0Model;
      this.component = { visible: true, type: 'edit', title: '预约率-车辆' };
    },
    contactMange1() {
      let res = this.topFilterList.find(x => x.fieldName === 'startTime|stopTime').initialValue;
      this.editData = res;
      this.componentName = contactMange1Model;
      this.component = { visible: true, type: 'edit', title: '临近准时交车率' };
    },
    // contactMange2(){
    //   this.editData = this.selectData;
    //   this.componentName = contactMange2Model;
    //   this.component = { visible: true, type: 'edit', title: '钣喷准时交车率' };
    // },
    contactMange3() {
      let res = this.topFilterList.find(x => x.fieldName === 'startTime|stopTime').initialValue;
      this.editData = res;
      this.componentName = contactMange3Model;
      this.component = { visible: true, type: 'edit', title: '钣喷快修交车率' };
    },
    contactMange4() {
      let res = this.topFilterList.find(x => x.fieldName === 'startTime|stopTime').initialValue;
      this.editData = res;
      this.componentName = contactMange4Model;
      this.component = { visible: true, type: 'edit', title: '机修快保交车率' };
    },
    // 车型总汇
    VehicleConfluence() {
      this.editData = this.selectData;
      this.componentDrawerName = VehicleConfluenceModel;
      this.componentDrawer = { visible: true, type: 'edit', title: '车型汇总' };
    },
    // 车牌总汇
    PlateConfluence() {
      this.editData = this.selectData;
      this.componentDrawerName = PlateConfluenceModel;
      this.componentDrawer = { visible: true, type: 'edit', title: '车牌汇总' };
    },
    // 项目材料明细
    ProjectMaterialDetails() {
      this.editData = this.tableData;
      console.log(this.editData, '项目材料明细单行值');
      this.componentDrawerName = ProjectMaterialDetailsModel;
      this.componentDrawer = { visible: true, type: 'edit', title: '项目材料明细' };
    },
    // 客户车辆明细
    CustomerVehicleDetails() {
      this.editData = this.selectData;
      this.componentDrawerName = CustomerVehicleDetailsModle;
      this.componentDrawer = { visible: true, type: 'edit', title: '客户车辆明细' };
    },
    // ikey故障
    ikeyFault() {
      console.log('+++++++++++++++++++++++++++++++++++', this.tableData);
      if (this.tableData && this.tableData.length > 0) {
        this.editData = this.tableData;
        this.componentDrawerName = ikeyFaultModle;
        this.componentDrawer = { visible: true, type: 'edit', title: 'service key故障' };
      } else {
        this.$notify.warning({ title: '提示信息', message: '请先选择一条数据' });
      }
    },
    Entering() {
      this.editData = this.selectData;
      this.componentDrawerName = enteringModel;
      this.componentDrawer = { visible: true, type: 'edit', title: '委托书' };
    },
    CarRepairThing() {
      this.editData = this.selectData;
      this.componentDrawerName = CarRepairThingModle;
      this.componentDrawer = { visible: true, type: 'edit', title: '车辆维修信息统计' };
    },
    selectDataList(val) {
      this.tableData = val;
      this.selectColumns = val;
      if (val.length > 0) {
        if (val[0].IS_ENERGY_VEHICLE == 10041001) {
          this.enerdydisabled = false;
        } else {
          this.enerdydisabled = true;
        }
      } else {
        this.enerdydisabled = true;
      }
    },
    addHandle() {
      // 新建
      this.handleType = 'add';
      // this.formData = row;
      this.showHandler();
    },
    // resetChange() {
    //   this.topFilterList.forEach(x => {
    //     if (x.fieldName === 'REPAIR_TYPE') {
    //       x.hidden = false;
    //     } else if (x.fieldName === 'flag') {
    //       x.hidden = false;
    //       x.initialValue = '';
    //     } else {
    //       x.hidden = true;
    //     }
    //   });
    //   this.topFilterList = [...this.topFilterList];
    // },
    editHandle(row) {
      this.handleType = 'edit'; // 编辑

      this.showHandler();
    },
    changeHandle(val) {
      if (val.LICENSE || val.VIN || val.startTime || val.stopTime || val.RO_NO || val.SERIES_CODE || val.MODEL_CODE) {
        if (val.LICENSE && val.LICENSE.length < 4) {
          return this.$notify.warning({ title: '提示信息', message: '车牌号至少输入4位搜索！' });
        }
        if (val.VIN && val.VIN.length < 4) {
          return this.$notify.warning({ title: '提示信息', message: '底盘号至少输入4位搜索！' });
        }
        if (val.startTime || val.stopTime) {
          let diffMonth = moment(val.stopTime).diff(moment(val.startTime), 'months');
          // let diffDay = moment(val.stopTime).diff(moment(val.startTime), 'days');
          // console.log(val.stopTime, val.startTime, diffMonth, diffDay, '月份跨度差值');
          if (diffMonth > 5) return this.$notify.warning({ title: '提示信息', message: '送修起止日期跨度不能超过半年' });
        }

        this.queryMainTableData();
      } else {
        this.$notify.warning({ title: '提示信息', message: '请至少填写一种搜索条件！' });
      }
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.$refs.table && this.$refs.table.EXECUTE_RESET_HEIGHT();
      });
    },
    // async saveDialog() {
    //   let res = {};
    //   if(this.tableData==null) return
    //   res = await addCustomeRgradeUpdatet({customeRgradeUpdateDTOList:this.tableData });
    //   if (res.resultCode === 200) {
    //     this.closeDialog('refresh');
    //   }
    // },
    // 关闭小功能面板
    closeComponentName(val, type) {
      this.component.visible = val;
      // 重置 editData
      this.editData = {};
      // 执行刷新
      type === 'refresh' && this.refreshHandle();
    },
    showHandler() {
      // 显示
      this.dialogTitle = `查看结算记录`;
      this.visible = true;
    },
    // 关闭小功能抽屉组件
    closeComponentDrawerName(val, type) {
      this.componentDrawer.visible = val;
      // 重置 editData
      this.editData = {};
      // 执行刷新
      type === 'refresh' && this.refreshHandle();
    },

    closeHandlerSBQY() {
      this.showSBQYDrawer = false;
    },

    closeHandler(val, type) {
      // 关闭
      this.visible = val;
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
        this.queryMainTableData();
      }
    },
    // 新能源
    xnyLr() {
      this.SBList['roNo'] = this.tableData[0].RO_NO;
      this.SBList['vin'] = this.tableData[0].VIN;
      this.SBList['createTime'] = this.tableData[0].RO_CREATE_DATE;
      this.XNYAttribute = true;
    },
    closeXNY(val) {
      this.XNYAttribute = false;
    },
    // 查询table主数据
    async queryMainTableData() {
      let formParams = await this.$refs.topFilter.GET_FORM_DATA();
      this.$refs.table.START_LOADING();
      console.log(formParams[1]);
      let params = Object.assign({}, formParams[1], { xhrAbort: false });
      console.log(params, 'fetchApi');

      if (this.mainTableIsLoading) return;
      this.mainTableIsLoading = true;
      try {
        let res = await this.fetchApi(params || {});
        if (res.resultCode == 200) {
          this.tableDataList = res.data;
          // 查询台次
          getQueryEnterSituationNum(params || {}).then(res => {
            if (res.resultCode == 200) {
              this.showEnterSituationNum = true;
              this.enterSituationNum = res.data.TOTAL_NUM;
              console.log(res, 'getQueryEnterSituationNum');
            }
          });
        }
      } catch (err) {
        console.log(err, '查询table主数据失败');
      } finally {
        this.mainTableIsLoading = false;
        this.$refs.table.STOP_LOADING();
      }
    },
    // 点击查看服务业绩统计汇总
    async handleCheckServicePerformance() {
      let filterData = await this.$refs.topFilter.GET_FORM_DATA();
      if (filterData[1].LICENSE || filterData[1].VIN || filterData[1].startTime || filterData[1].stopTime || filterData[1].RO_NO) {
        if (filterData[1].LICENSE && filterData[1].LICENSE.length < 4) {
          return this.$notify.warning({ title: '提示信息', message: '车牌号至少输入4位搜索！' });
        }
        if (filterData[1].VIN && filterData[1].VIN.length < 4) {
          return this.$notify.warning({ title: '提示信息', message: '底盘号至少输入4位搜索！' });
        }
        this.summaryFetchParams = filterData[1];
        this.summaryDialogVisible = true;
      } else {
        this.$notify.warning({ title: '提示信息', message: '请至少填写一种搜索条件！' });
      }
    },
    // 查询服务参数
    async queryRepairParams() {
      let res = await findAllRepair();
      if (res.resultCode == 200) {
        this.repairParams = res.data;
      }
    }
  }
};
</script>
